package com.admin.controller.admin.monitor;

import com.system.constant.HTTPStatus;
import com.system.response.Result;
import com.system.response.monitor.logs.LogininforDtoResponse;
import com.system.service.monitor.logs.SysLogininforService;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;

/**
 * @Classname SysLogininforController
 * @Date 2023/8/3 14:48
 * @Created ZFC
 */
@RestController
@RequestMapping("/sys/log/logininfor")
public class SysLogininforController {

    @Autowired
    private SysLogininforService logininforService;

    @Cacheable(
            value = "logininfor",
            key = "#logininforDto.pageSize +'::'+ #logininforDto.pageNum +'::'+ " +
                    "#logininforDto.ipaddr +'::'+ #logininforDto.username +'::'+ " +
                    "#logininforDto.status +'::'+ #logininforDto.startTime +'::'+ " +
                    "#logininforDto.endTime"
    )
    @ApiOperation("条件查询操作日志")
    @GetMapping("/list")
    public Result list(LogininforDtoResponse logininforDto) {

        return logininforService.selectLogininforList(logininforDto);
    }

    @RequiresPermissions("admin:logininfor:delete")
    @DeleteMapping("/deleteLogininfor")
    public Result deleteOperLogByIds(@NotNull(message = "参数为空") Long[] ids) {
        return logininforService.deleteLogininforByIds(ids);
    }

    @RequiresPermissions("admin:logininfor:clear")
    @DeleteMapping("/clear")
    public Result clearOperLog() {
        return logininforService.clearLogininfor();
    }

    @CacheEvict(
            value = "logininfor",
            allEntries = true
    )
    @DeleteMapping("/clearCache")
    public Result clearCache() {
        return new Result().setCode(HTTPStatus.SUCCESS).setMessage("清空成功！");
    }


}
